package com.yand.disk.demo.config;


import com.yand.disk.demo.entity.FileInfoBean;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import redis.clients.jedis.JedisPool;

import java.sql.Date;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;


/**
 * @author  yanzz
 * 初始化模拟文件信息，正常系统文件信息都是存在数据库中
 */
@Configuration
public class FileInfoConfig {

    //id
    @Value("${downLoadUrl.id}")
    private  String id;

    @Value("${downLoadUrl.createTime}")
    private  String createTime;

    @Value("${downLoadUrl.uuid}")
    private  String uuid;

    @Value("${downLoadUrl.expireTime}")
    private  String  expireTime;

    @Value("${downLoadUrl.downLoadCount}")
    private  String downLoadCount;

    @Value("${downLoadUrl.filePath}")
    private  String filePath;

/*    @Value("${file.verifyMode}")
    private  String verifyMode;*/

    @Value("${downLoadUrl.isCode}")
    private  String isCode;

    @Value("${downLoadUrl.identifyingCode}")
    private  String identifyingCode;

    public static FileInfoBean fileInfoBean = null;


    /**
     * 生成FileInfoBean文件对象
     * @return
     */
    @Bean
    public  FileInfoBean getFileInfoBean(){
        DateTimeFormatter df  = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        ZonedDateTime zonedDateTime = LocalDate.parse(createTime,df).atStartOfDay(ZoneId.systemDefault());


        fileInfoBean = FileInfoBean.builder().id(Long.parseLong(id)).createTime(Date.from(zonedDateTime.toInstant()))
                .expireTime(Long.parseLong(expireTime)).downLoadCount(Integer.parseInt(downLoadCount))
                .uuid(uuid)
                .filePath(filePath)
                .isCode(Integer.parseInt(isCode))
                .identifyingCode(identifyingCode).build();
        return fileInfoBean;

    }









}
